home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 1.iso / HENSA / MATHS / PLPLOT / PLPLOT.ZIP / examples / C / x04c.c < prev    next >
C/C++ Source or Header  |  1994-06-30  |  2KB  |  80 lines

  1. /* $Id: x04c.c,v 1.7 1994/06/30 17:57:14 mjl Exp $
  2.  * $Log: x04c.c,v $
  3.  * Revision 1.7  1994/06/30  17:57:14  mjl
  4.  * All C example programs: made another pass to eliminate warnings when using
  5.  * gcc -Wall.  Lots of cleaning up: got rid of includes of math.h or string.h
  6.  * (now included by plplot.h), eliminated redundant casts, put in more
  7.  * uniform comments, and other minor changes.
  8.  *
  9.  * Revision 1.6  1994/03/30  07:21:47  mjl
  10.  * Changes to all C example programs: special handling for malloc re: header
  11.  * files eliminated, include of stdio.h and stdlib.h eliminated (now done
  12.  * by plplot.h), include of "plplot.h" changed to <plplot.h> to enable
  13.  * simpler builds by the general user, some cleaning up also.
  14. */
  15.  
  16. /*    x04c.c
  17.  
  18.     Log plot demo.
  19. */
  20.  
  21. #include <plplot.h>
  22.  
  23. /*----------------------------------------------------------------------*\
  24.  * main
  25.  *
  26.  * Illustration of logarithmic axes, and redefinition of window.
  27. \*----------------------------------------------------------------------*/
  28.  
  29. int
  30. main(int argc, char *argv[])
  31. {
  32.     int i;
  33.     static PLFLT freql[101], ampl[101], phase[101];
  34.     PLFLT f0, freq;
  35.  
  36. /* Parse and process command line arguments */
  37.  
  38.     (void) plParseInternalOpts(&argc, argv, PL_PARSE_FULL);
  39.  
  40. /* Initialize plplot */
  41.  
  42.     plinit();
  43.  
  44.     pladv(0);
  45.     plfont(2);
  46.  
  47.     f0 = 1000.0;
  48.     for (i = 0; i <= 100; i++) {
  49.     freql[i] = 1.0 + i / 20.0;
  50.     freq = pow(10.0, freql[i]);
  51.     ampl[i] = 20.0 * log10(1.0 / sqrt(1.0 + pow((freq / f0), 2.)));
  52.     phase[i] = -(180.0 / 3.141592654) * atan(freq / f0);
  53.     }
  54.  
  55.     plvpor(0.15, 0.85, 0.1, 0.9);
  56.     plwind(1.0, 6.0, -80.0, 0.0);
  57.     plcol(1);
  58.     plbox("bclnst", 0.0, 0, "bnstv", 0.0, 0);
  59.     plcol(2);
  60.     plline(101, freql, ampl);
  61.     plcol(1);
  62.     plptex(5.0, -30.0, 1.0, -20.0, 0.5, "-20 dB/decade");
  63.  
  64.     plwind(1.0, 6.0, -100.0, 0.0);
  65.     plbox("", 0.0, 0, "cmstv", 30.0, 3);
  66.     plcol(3);
  67.     plline(101, freql, phase);
  68.  
  69.     plcol(1);
  70.     plmtex("b", 3.2, 0.5, 0.5, "Frequency");
  71.     plmtex("t", 2.0, 0.5, 0.5, "Single Pole Low-Pass Filter");
  72.     plcol(2);
  73.     plmtex("l", 5.0, 0.5, 0.5, "Amplitude (dB)");
  74.     plcol(3);
  75.     plmtex("r", 5.0, 0.5, 0.5, "Phase shift (degrees)");
  76.  
  77.     plend();
  78.     exit(0);
  79. }
  80.